package com.carryGo.web.hzl;

import com.carryGo.entity.Commodity;
import com.carryGo.entity.PageManager;
import com.carryGo.service.dp.CommodityService;
import com.carryGo.utils.hzl.WebUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * ClassName:PageServlet
 * package:com.carryGo.web.hzl
 * Description:
 *
 * @Date:2020/8/29 10:02
 * @Author: tank_黄志凌
 */
@WebServlet("/pageHzl")
public class PageServlet extends HttpServlet {

    private CommodityService commodityService=new CommodityService();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String method=request.getParameter("method");
        switch (method){
            case "toFoodPage":
            toFoodPage(request,response);
            break;
        }
    }

    private void toFoodPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PageManager pm = WebUtils.getBean(PageManager.class,request);
        List<Commodity> commodities=commodityService.queryCommodities(pm);
        System.out.println(commodities);
        int totalCount=commodityService.queryUserTotalCount();
        pm.setTotalCount(totalCount);
        pm.setPages();
        request.setAttribute("pm",pm);
        request.setAttribute("commodities",commodities);
        WebUtils.toRequestPage(request,response,"foodPage");
    }
}
